import pandas as pd
from main import ExcelMatcher

def final_test():
    """最终测试修改后的匹配功能"""
    matcher = ExcelMatcher()
    
    print("=== 最终测试 ===")
    
    # 加载工资表
    print("\n1. 加载工资表...")
    salary_result = matcher.load_salary_file("d:/pycode/工资表.xlsx")
    print(f"工资表加载结果: {salary_result}")
    
    if salary_result:
        print(f"工资表列名: {list(matcher.salary_df.columns)}")
        print(f"工资表数据行数: {len(matcher.salary_df)}")
        print("工资表前3行姓名和工资标准:")
        for i in range(min(3, len(matcher.salary_df))):
            row = matcher.salary_df.iloc[i]
            print(f"  {row['姓名']}: {row.get('工资标准', 'N/A')}")
    
    # 加载钉钉文件夹
    print("\n2. 加载钉钉文件夹...")
    ding_result = matcher.load_ding_folder("d:/pycode/ding")
    print(f"钉钉文件夹加载结果: {ding_result}")
    
    if ding_result:
        print(f"钉钉表列名: {list(matcher.ding_df.columns)}")
        print(f"钉钉表数据行数: {len(matcher.ding_df)}")
        
        # 显示钉钉表的前几行数据
        print("\n钉钉表前3行关键数据:")
        for i in range(min(3, len(matcher.ding_df))):
            row = matcher.ding_df.iloc[i]
            # 找到姓名列（第3列）
            name_col = matcher.ding_df.columns[2] if len(matcher.ding_df.columns) > 2 else None
            name = row[name_col] if name_col else 'N/A'
            
            # 查找包含工资数据的列
            salary_data = []
            for col in matcher.ding_df.columns:
                val = row[col]
                try:
                    if pd.notna(val):
                        num_val = float(val)
                        if 1000 <= num_val <= 50000:
                            salary_data.append(f"{col}:{num_val}")
                except:
                    pass
            
            print(f"  姓名({name_col}): {name}")
            print(f"  可能的工资数据: {salary_data}")
    
    # 测试匹配功能
    if salary_result and ding_result:
        print("\n3. 测试数据匹配...")
        match_result = matcher.match_data()
        print(f"匹配结果: {match_result}")
        
        if match_result and matcher.result_df is not None:
            print(f"\n匹配后的数据行数: {len(matcher.result_df)}")
            print("前5行匹配结果:")
            for i in range(min(5, len(matcher.result_df))):
                row = matcher.result_df.iloc[i]
                print(f"  {row['姓名']}: 钉钉工资={row.get('钉钉中的工资标准', 'N/A')}, 匹配状态={row.get('是否匹配', 'N/A')}")

if __name__ == "__main__":
    final_test()